package models

import (
	"time"

	"github.com/google/uuid"
	"gorm.io/gorm"
)

type Bet struct {
	ID         string    `gorm:"primaryKey;type:varchar(255)" json:"id"`
	BetType    string    `gorm:"type:varchar(50);not null" json:"betType"`
	OddsValue  float64   `gorm:"type:decimal(10,2);not null;default:0.00" json:"oddsValue"`
	Result     string    `gorm:"type:varchar(255);not null" json:"result"`
	BetCount   float64   `gorm:"type:decimal(10,2);not null;default:0.00" json:"betCount"`
	BetAmount  float64   `gorm:"type:decimal(10,2);not null;default:0.00" json:"betAmount"`
	WinAmount  float64   `gorm:"type:decimal(10,2);not null;default:0.00" json:"winAmount"`
	IsWin      bool      `gorm:"type:boolean;not null;default:false" json:"isWin"`
	BatTime    time.Time `gorm:"type:timestamp;not null;default:CURRENT_TIMESTAMP" json:"batTime"`
	GameUserId string    `gorm:"type:varchar(255);not null;index" json:"gameUserId"` // 外键字段
	GameCode   string    `gorm:"type:varchar(255);not null;index" json:"gameCode"`
}

// TableName 返回 Bet 结构体对应的数据库表名
func (bet *Bet) TableName() string {
	return "bet"
}
func (bet *Bet) BeforeCreate(tx *gorm.DB) error {
	bet.ID = uuid.NewString()
	bet.BatTime = time.Now()
	return nil
}
